<?php
namespace app\admin\controller;

class Member extends Auth{
	public function __construct()
	{
		parent::__construct();
        $this->isLogin();
	}
	
	public function index()
	{
		//会员列表
		$nums = M('member')->select();
		$count= count($nums);
		$Page = $this->getPage($count,C('PAGE_NUMS'));
		$info = M('member')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('info',$info);
        

        return $this->fetch();
	}
	

	public function add()
	{

		if(IS_POST){
         $pwd = trim(I('post.pwd'));
		 $repwd = trim(I('post.repwd'));
           if($pwd === $repwd){
           	       $data['uname']=I('post.uname');
           	       $data['phone']=I('post.phone');
	           	   $data['pwd']=md5($pwd);
	           	   $data['login_time']=time();
	               $info = M('member')->add($data);
	                if($info){
	                	return $this->success('新增成功',U('Member/index'));
	                }else{
	                	return $this->error('新增失败',U('Member/index'));
	                }
		       }
		}

		return $this->fetch();
	}
	
	public function del($id)
	{
		$id=$id;
		$info = M('member')->where('id='.$id)->delete();
	            if($info){
	            	return $this->success('删除成功',U('Member/index'));
	            }else{
	            	return $this->error('删除失败',U('Member/index'));
	            }			
		
	}

	/**
	* 短信通知
	**/
	public function notice_jiangjia()
	{
		$count=M('message')->where('message_type=4')->count();
		$m_nums = M('message')->where('message_type=4')->getField('phone',true);
		$nums="";
		for($i=0;$i<=$count-1;$i++){
			$nums .=$m_nums[$i].",";
		}
		if(IS_POST){
		   if($_POST['kaiqi'] ==1){
		   	     $path ="modules/sendmsg.php";
                 $jiekou = unserialize(file_get_contents($path));
                 $uid = $jiekou['uid'];
                 $pwd = $jiekou['pwd'];
                 $mobile = $nums;
                 $content = $_POST['jiangjia'];
                 $sendMsg = new \org\Sendmsg();
                 $sendMsg->sendSMS($uid,$pwd,$mobile,$content);
		   }
		}
	
  
		return $this->fetch();
	}
	
	public function notice_kaipan()
	{

		$count=M('message')->where('message_type=5')->count();
		$m_nums = M('message')->where('message_type=5')->getField('phone',true);
		$nums="";
		for($i=0;$i<=$count-1;$i++){
			$nums .=$m_nums[$i].",";
		}
		if(IS_POST){
		   if($_POST['kaiqi'] ==1){
		   	     $path ="modules/sendmsg.php";
                 $jiekou = unserialize(file_get_contents($path));
                 $uid = $jiekou['uid'];
                 $pwd = $jiekou['pwd'];
                 $mobile = $nums;
                 $content = $_POST['kaipan'];
                 $sendMsg = new \org\Sendmsg();
                 $sendMsg->sendSMS($uid,$pwd,$mobile,$content);
		   }
		}
		return $this->fetch();
	}
	
	/**
	* 查看会员详细信息
	*/
  public function detail($mid)
  {
    $info = M('member')->where('id='.$mid)->select();
    $this->assign('info',$info);
  	return $this->fetch();
  }
	
	
	
	
	
	
	
	
	
}
